<?php

use kartik\widgets\FileInput;
use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use kartik\builder\Form;
use cza\base\widgets\ui\adminlte2\InfoBox;
use cza\base\models\statics\EntityModelStatus;

$regularLangName = \Yii::$app->czaHelper->getRegularLangName();
$messageName = $model->getMessageName();
?>

<?php
$uid = Yii::$app->request->get('uid');
$user = \common\models\c2\entity\FeUser::find()
    ->where(['id' => $uid])
    ->with('community')
    ->with(['idcardFront' => function ($q) {
        $q->where(['entity_class' => \common\models\c2\entity\FeUser::className(), 'entity_attribute' => 'idcard_front']);
    }])->with(['idcardBack' => function ($q) {
        $q->where(['entity_class' => \common\models\c2\entity\FeUser::className(), 'entity_attribute' => 'idcard_back']);
    }])->one();
?>

<div class="container-fluid" style="background-color: #d0e9c6">
    <div class="row">
        <div class="col-md-3">
            <?php
            echo '<label class="control-label">身份证正面</label>';
            echo FileInput::widget([
                'name' => 'idcardFront',

                // 'disabled' => true,
                'options' => [
                    'multiple' => false,

                ],
                'pluginOptions' => [

                    'initialPreview' => [
                        // OSS_URL . '/' . $user->idcardFront->url,
                        $user->getAttachmentUrl('idcard_front'),
                    ],
                    'initialPreviewAsData' => true,
                    'initialPreviewConfig' => [
                    ],
                    'overwriteInitial' => false,
                    'maxFileSize' => 2800,
                ]
            ]);
            ?>
        </div>
        <div class="col-md-3">
            <?php
            echo '<label class="control-label">身份证反面</label>';
            echo FileInput::widget([
                'name' => 'idcardBack',
                'options' => [
                    'multiple' => true
                ],
                'pluginOptions' => [
                    'initialPreview' => [
                        // OSS_URL . '/' . $user->idcardBack->url,
                       $user->getAttachmentUrl('idcard_back'),
                    ],
                    'initialPreviewAsData' => true,
                    'initialPreviewConfig' => [
                    ],
                    'overwriteInitial' => false,
                    'maxFileSize' => 2800,
                    'showUpload' => false
                ]
            ]);
            ?>
        </div>
        <div class="col-md-3">
            <?php
            echo '<label class="control-label">房产证</label>';
            echo FileInput::widget([
                'name' => 'estate',
                'options' => [
                    'multiple' => true
                ],
                'pluginOptions' => [
                    'initialPreview' => [
                        $user->getAttachmentUrl('estate'),
                    ],
                    'initialPreviewAsData' => true,
                    'initialPreviewConfig' => [
                    ],
                    'overwriteInitial' => false,
                    'maxFileSize' => 2800,
                    'showUpload' => false
                ]
            ]);
            ?>
        </div>
    </div>

    <div style="font-size: 20px">

        <div>申请人姓名：<?= $user->username ?></div>
        <div>申请人小区：<?= $user->community->name ?></div>
        <div>申请人手机号码：<?= $user->mobile_number ?></div>
        <div>申请人地址：<?= $user->address ?></div>
        <div>申请人账号状态：<?= $user->status == EntityModelStatus::STATUS_ACTIVE ? '正常' : '待审核' ?></div>
    </div>


</div>


<?php
$form = ActiveForm::begin([
    'action' => ['audit', 'id' => $model->id, 'uid' => $uid],
    'options' => [
        'id' => $model->getBaseFormName(),
        'data-pjax' => true,
    ]]);
?>

<div class="<?= $model->getPrefixName('form') ?>
">
    <?php if (Yii::$app->session->hasFlash($messageName)): ?>
        <?php if (!$model->hasErrors()) {
            echo InfoBox::widget([
                'withWrapper' => false,
                'messages' => Yii::$app->session->getFlash($messageName),
            ]);
        } else {
            echo InfoBox::widget([
                'defaultMessageType' => InfoBox::TYPE_WARNING,
                'messages' => Yii::$app->session->getFlash($messageName),
            ]);
        }
        ?>
    <?php endif; ?>

    <div class="well">
        <?php
        echo Form::widget([
            'model' => $model,
            'form' => $form,
            'columns' => 3,
            'attributes' => [
                'community_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => \common\models\c2\entity\Community::getHashMap('id2', 'name'), 'options' => ['placeholder' => $model->getAttributeLabel('community_id')]],
                'building_number_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => \common\models\c2\entity\BuildingNumber::getHashMap('id2', 'name'), 'options' => ['placeholder' => $model->getAttributeLabel('building_number_id')]],
                'unit_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => \common\models\c2\entity\Unit::getHashMap('id2', 'name'), 'options' => ['placeholder' => $model->getAttributeLabel('unit_id')]],
                'houses_id' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => \common\models\c2\entity\House::getHashMap('id2', 'name'), 'options' => ['placeholder' => $model->getAttributeLabel('unit_id')]],
                'name' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('name')]],
                'phone' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('phone')]],
                'sy_validity_start' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('sy_validity_start')]],
                'sy_validity_end' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('sy_validity_end')]],
                'remarks' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('remarks')]],
                'gender' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('gender')]],
                'country' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('country')]],
                'nation' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('nation')]],
                'birthday' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('birthday')]],
                'id_type' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => \common\models\c2\statics\CertificatesType::getHashMap('id', 'label')],
                'id_number' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('id_number')]],
                'validity_start' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('validity_start')]],
                'validity_end' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('validity_end')]],
                'id_address' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('id_address')]],
                'Issuing_authority' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('Issuing_authority')]],
                'hukou' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('hukou')]],
                'work_unit' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('work_unit')]],
                'bound_vehicle' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('bound_vehicle')]],
            ]
        ]);
        echo Html::beginTag('div', ['class' => 'box-footer']);
        echo Html::submitButton('<i class="fa fa-save"></i> ' . Yii::t('app.c2', 'Save'), ['type' => 'button', 'class' => 'btn btn-primary pull-right']);
        echo Html::a('<i class="fa fa-arrow-left"></i> ' . Yii::t('app.c2', 'Go Back'), ['index'], ['data-pjax' => '0', 'class' => 'btn btn-default pull-right', 'title' => Yii::t('app.c2', 'Go Back'),]);
        echo Html::endTag('div');
        ?>
    </div>
</div>
<?php ActiveForm::end(); ?>
